<template>
  <div class="vue-box sbot sbot-fluid">
    <!-- 参数栏 -->
    <div class="c-panel">
      <el-form :inline="true">
        <!-- 表单 -->
        <sa-item v-model="m.avatar" type="img" name="头像" br />
        <sa-item v-model="m.nickName" type="text" name="昵称" br />
        <sa-item v-model="m.name" type="text" name="用户名" br />
        <sa-item v-model="m.phone" type="num" name="手机" br max-length="11" />
        <sa-item name="角色" br>
          <el-select v-model="m.roleId" :disabled="m.isLock === 1">
            <el-option label="请选择" :value="0" disabled />
            <el-option v-for="role in roleList" :key="role.id" :label="role.name" :value="role.id" />
          </el-select>
        </sa-item>
        <sa-item v-model="m.status" type="enum" jtype="3" :jv="dims.YES_OR_NO" name="启用状态"
          :disabled="m.id == sa.$sys.getCurUser().id" br />
        <sa-item v-model="m.note" type="text" name="描述" br />
        <sa-item v-model="m.sort" type="num" name="序号" br />
        <sa-item name="" br class="s-ok">
          <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
        </sa-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import sa from '@/sa-frame/sa';
export default {
  name: 'acc-update',
  props: { param: Object },
  data() {
    return {
      // 超级对象
      m: this.createModel(),
      roleList: [],
      // 缓存字典
      dims: {},
    }
  },
  created: function () {
    let gd = sa.$sys.getCurd()
    if (gd) {
      this.dims = gd
    } else {
      sa.error('未获取到字典信息！');
    }
    this.roleList = this.param.roleList
  },
  methods: {
    createModel() {
      return {
        id: this.param.id,
        name: this.param.name,
        nickName: this.param.nickName,
        avatar: this.param.avatar,
        phone: this.param.phone,
        roleId: this.param.roleId,
        status: this.param.status,
        note: this.param.note,
        sid: this.param.sid,
        sort: this.param.sort,
        isLock: this.param.isLock
      }
    },
    // 变更
    ok: function () {
      // 表单校验
      let m = this.m;
      sa.checkNull(m.avatar, '请选择一个头像');
      sa.checkNull(m.name, '请输入昵称');
      sa.checkNull(m.phone, '请输入电话号码');
      sa.checkNull(m.roleId, '请选择角色');


      // 添加
      sa.ajax('/sso/acc/update', m, function (res) {
        sa.alert('变更成功, 账号为：' + m.name, function () {
          this.m = this.createModel();
          sa.closeModel();
          sa.currView().f5();
        }.bind(this));
      }.bind(this), { type: "post" });
    }
  }
}
</script>

<style scoped></style>
